<template>
	<view>
		<view>
			<view class="p_title">请描述你的病情</view>
			<up-textarea v-model="FormState.illness" placeholder="请输入内容" ></up-textarea>
		</view>
			  <up-checkbox
				   v-model:checked="FormState.guide"
					label="是否需要医生指导用药"
				   usedAlone
			  />
		  <view>
			  <view class="p_title">上传检查报告或患处照片</view>
			<!--  	<up-upload
			  		name="1"
			  		multiple
			  		:maxCount="10"
			  	></up-upload> -->
				<view class="upImg" v-if='!imgSrc' @click="selImg">
					＋
				</view>
				<image class="upImg" v-if='imgSrc' :src="imgSrc"></image>
		  </view>
		  <view class="selPainter">
			  <view class="p_title">选择就诊人</view>
			  <view class="per_info">
				 <image src="../../static/gift.png"></image>
				 <view v-if="nowPain.name">{{nowPain.name}}</view>
				 <navigator  style="color:blue;"  url="/pages/addperson/list">
				    重新选择
				 </navigator>
			   </view>
		  </view>
		  <view class="view_btn">
			  <up-button :customStyle="{marginTop:'10px'}" text="取消" type="error" ></up-button>
			   <up-button @click="toSend" :customStyle="{marginTop:'10px'}"  type="primary" text="确定"></up-button>
		  </view>
	</view>
</template>

<script setup>
	import {ref,computed,reactive} from 'vue'
	import {painStore} from '@/store/painer.js'
	import {toWenzhenApi} from '@/api/user'
	let value1=ref('')
	let selVal=ref('')
	// 获取pinia中   存储的就诊人
	let pStore=painStore();
	let nowPain=computed(()=>pStore.painer) //就诊人
	console.log(nowPain,"---------pinia中 的就诊人信息")
	
	let imgSrc=ref('')//选择的图片地址
	let selImg=()=>{
		// 小程序选择媒体文件的api
		uni.chooseMedia({
			success(res){
				console.log(res,"--------")
				imgSrc.value=res.tempFiles[0].tempFilePath
				FormState.ins_report.push(imgSrc.value)//存储患处照片
			}
		})
	}

	let FormState=reactive({
		illness:"",//病情描述
		guide:false,//是否需要医生指导用药，true:需要，false:不需要
		ins_report:[]//图片数组
	})
	let toSend=async ()=>{
		console.log(FormState)
			console.log(nowPain.value._id,"-----sdf--------")
		FormState.patient_id=nowPain.value._id;//就诊人id  //vue3 计算属性 要使用.value操作
		 let res=await toWenzhenApi(FormState);
		 console.log(res,"------问诊接口---------")
		 uni.showToast({
		 	title:"提交问诊成功"
		 })
		 uni.switchTab({
		 	url:"/pages/home/index"
		 })
	}
	
	
</script>

<style lang="scss">
	.p_title{
		font-size: 20px;
		font-weight: bold;
	}
	.per_info{
		display: flex;
		justify-content: space-around;
		height: 180rpx;
		background: pink;
		align-items: center;
		image{
			width: 120rpx;
			height: 120rpx;
			
		}
	}
	.upImg{
		width: 200rpx;
		height: 200rpx;
		border: 1px solid black;
		font-size: 100rpx;
		text-align: center;
		line-height: 200rpx;
	}
</style>